/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   OSEndianTools.hpp. Created on: 15.06.2009 13:04:20
*/


#ifndef OSENDIANTOOLS_HPP_
#define OSENDIANTOOLS_HPP_

#include "cpputils/CppUtils.hpp"

namespace cpputils {
	namespace utils {

		/**
		 * Auxiliary static functions for big/little endian conversations
		 */
		class OSEndianTools {
		private:
			union FloatIntFormat {
				float fValue;
				boost::uint32_t nValue;
			};

			union DoubleIntFormat {
				double fValue;
				boost::uint64_t nValue;
			};

		public:
			inline static boost::int16_t network_to_host(boost::int16_t value);
			inline static boost::int32_t network_to_host(boost::int32_t value);
			inline static boost::int64_t network_to_host(boost::int64_t value);
			inline static boost::uint16_t network_to_host(boost::uint16_t value);
			inline static boost::uint32_t network_to_host(boost::uint32_t value);
			inline static boost::uint64_t network_to_host(boost::uint64_t value);

			inline static float network_to_host(float value);
			inline static double network_to_host(double value);

			inline static boost::int16_t host_to_network(boost::int16_t value);
			inline static boost::int32_t host_to_network(boost::int32_t value);
			inline static boost::int64_t host_to_network(boost::int64_t value);
			inline static boost::uint16_t host_to_network(boost::uint16_t value);
			inline static boost::uint32_t host_to_network(boost::uint32_t value);
			inline static boost::uint64_t host_to_network(boost::uint64_t value);

			inline static float host_to_network(float value);
			inline static double host_to_network(double value);

			inline static bool isBigEndianArch();
			inline static bool isLittleEndianArch();

		};
	}
}

#include "OSEndianTools.inl"

#endif /* OSENDIANTOOLS_HPP_ */
